/**
*      author: Y_Yao
*      created: 2025-02-26 11:26:39
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int n;
int ans = 1;
unordered_map<int,int> fa;

int find(int x)
{
    if(fa[x] == x) return x;
    else fa[x] = find(fa[x]);
    return fa[x];
}

void Union(int u,int v)
{
    // u = find(u);
    // v = find(v);
    // if(u == v) return;
    // if(sz[u] > sz[v]) swap(u,v);
    // fa[u] = v;
    // sz[v] += sz[u];
    fa[find(u)] = fa[find(v)];
} 

void solve()
{
    cin >> n;
    fa[1] = 1;
    for(int i = 1;i <= n;i++)
    {
        int x,y;
        cin >> x >> y;
        if(!fa.count(x)) fa[x] = x;
        if(!fa.count(y)) fa[y] = y;
        Union(x,y);
    }
    for(auto& e : fa)
    {
        int i = e.first;
        if(find(i) == find(1))
        {
            ans = max(ans,i);
        }
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}